package com.netstar.salesman_90dsp.config;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

import android.os.Environment;

import com.netstar.salesman_90dsp.model.UserModel;

/**
 * 基本配置
 * 
 * @author Administrator
 * 
 */
public class DefaultConfig {
	/**
	 * sharedprefernce 配置文件的名称
	 */
	public static String DefaultConfigFileName = "DefaultConfigFile";
	/**
	 * 列表可以看几行
	 */
	public static int listShowRowNum = 20;
	/**
	 * 用户信息
	 */
	public static UserModel userModel;
	/**
	 * 在sdcard中的根路径
	 */
	public static File docShareRootDirFile = new File(
			Environment.getExternalStorageDirectory(), "DocShare");
	/**
	 * 下载文件路径
	 */
	public static File docShareDownloadDirFile = new File(docShareRootDirFile,
			"download");
	/**
	 * 阅读文件缓存路径
	 */
	public static File docSharePageCacheDirFile = new File(docShareRootDirFile,
			"cache");
	static {
		if (!docShareDownloadDirFile.exists()) {
			try {
				FileUtils.forceMkdir(docShareDownloadDirFile);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if (!docSharePageCacheDirFile.exists()) {
			try {
				FileUtils.forceMkdir(docSharePageCacheDirFile);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			/*
			 * 如果存在，就先清空缓存
			 */
			new Thread(new Runnable() {
				@Override
				public void run() {
					try {
						// 先删除文件夹
						FileUtils.deleteDirectory(docSharePageCacheDirFile);
						// 在创建文件夹
						FileUtils.forceMkdir(docSharePageCacheDirFile);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}).start();
		}
	}
}
